package com.tcm.controller.front;

import com.tcm.entity.resp.R;
import com.tcm.service.ItemStudentService;
import com.tcm.utils.AccessTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 学生练习记录控制器
 * @author Guqier
 * @version 1.0
 * @date 2023/9/2 19:02
 */
@RestController
@RequestMapping("/stu")
public class StuItemStudentController {

    @Autowired
    private ItemStudentService itemStudentService;

    /**
     * 获取练习记录
     * @param request 请求对象
     * @return 练习记录
     */
    @RequestMapping(value = "/history", method = RequestMethod.GET)
    public R getChapterExerciseHistory(HttpServletRequest request){
        return R.success(itemStudentService.getChapterExerciseHistory(AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取错题列表
     * @param request 请求对象
     * @return 错题列表
     */
    @RequestMapping(value = "/wrong", method = RequestMethod.GET)
    public R getWrongItemList(HttpServletRequest request){
        return R.success(itemStudentService.getWrongItemList(AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 获取错题详细
     * @param current 当前题数
     * @param request 请求对象
     * @return 错题详细
     */
    @RequestMapping(value = "/wrong/detail", method = RequestMethod.GET)
    public R getWrongItemDetail(@RequestParam Integer current, HttpServletRequest request){
        return R.success(itemStudentService.getWrongItemDetail(current, AccessTokenUtil.getUserAccount(request)));
    }

}
